package com.jfinal.aceadmin.model;
import java.util.ArrayList;
import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Repository;

import com.jfinal.aceadmin.util.VoUtil;
import com.jfinal.aceadmin.vo.TaskVo;
@Repository
public class UserTaskImpl{
	private static ApplicationContext ctx;
	
	public static UserTaskImpl getDAO() {
		if (null == ctx) {
			ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
		}
		UserTaskImpl instance =  ctx.getBean(UserTaskImpl.class);
		return instance;
	}

	/**
	 * Get user tasks info
	 * @param userId
	 * @return
	 */
	public List<TaskVo> getTasks(int userId) {
		List<UserTask> uTasks = UserTask.dao.findByUserId(userId);
		List<TaskVo> taskVos = new ArrayList<TaskVo>();
		for(UserTask uTask : uTasks){
			TaskVo taskVo = VoUtil.convert(uTask);
			taskVos.add(taskVo);
		}
		return taskVos;
	}
}